layui.use(['layer'],function () {
    var $=layui.jquery,layer=layui.layer;
    $(".custom-fwsm").html($("input[name='fwsm']").val());
    $(".custom-fwlc").html($("input[name='lcsm']").val());
    var id=$("input[name='id']").val();
    $(".layui-custom-scfw").on("click",function () {
        yhdy(id);
    });
    $(".layui-custom-qxsc").on("click",function () {
        fwqx(id);
    });
    
    function yhdy(id) {
        $.ajax({
            type:'GET',
            url:'/uc/service/'+id+'/yhdy',
            async: false,
            dataType: "json",
            error: function (request) {
                console.log("Connection error")
            },
            success:function (data) {
                if(null!=data&&data.result){
                    $(".layui-custom-right").html("<div class='layui-btn layui-btn-danger layui-btn-small layui-custom-qxsc'>取消收藏</div>");
                    $(".layui-custom-qxsc").on("click",function () {
                        fwqx(id);
                    });
                    $(".fwzt").html("已收藏");
                    layer.msg("收藏成功！");
                }
            }
        });
    }
    function fwqx(id) {
        $.ajax({
            type:'GET',
            url:'/uc/service/'+id+'/qxsc',
            async: false,
            dataType: "json",
            error: function (request) {
                console.log("Connection error")
            },
            success:function (data) {
                if(null!=data&&data.result){
                    $(".layui-custom-right").html("<div class='layui-btn layui-btn-normal layui-btn-small layui-custom-scfw'>收藏服务</div>");
                    $(".layui-custom-scfw").on("click",function () {
                        yhdy(id);
                    });
                    $(".fwzt").html("未收藏");
                    layer.msg("取消成功！");
                }
            }
        });
    }
});